import { Adapter, Renderer } from "../renderer/adapter";
import { App_Interface } from "./app_interface";


export class App_Framework implements App_Interface.IFramework {
    userCode: App_Interface.IUserCode;
    render: Renderer.RenderWebgl
    constructor(userCode: App_Interface.IUserCode, webgl: WebGLRenderingContext) {
        this.userCode = userCode;
        this.render = new Renderer.RenderWebgl(webgl);
    }
    public async Init(): Promise<void> {
        await this.userCode.OnInit(this);

        requestAnimationFrame(() => {
            this.Update();
        });
    }
    public Update(): void {
        //this.render.Begin();

        this.userCode.OnUpdate(this);
        requestAnimationFrame(() => {
            this.Update();
        });

        //this.render.End();

    }
    public ResizeCanvas(): void {
        this.render.target_Canvas.OnResize();
        this.userCode.OnResize(this);
    }
}

